#!/bin/bash

install_site() {
  # runtime
  ansible -i hosts runtime -m shell -a 'curl -O https://dl.cloudos.yihecloud.com/release/cloudos-script.tar.gz && tar zvxf cloudos-script.tar.gz'
  ansible -i hosts runtime -m shell -a './install.sh runtime'

  # init
  ansible -i hosts all:\!runtime  -m shell -a 'curl -Ls http://192.168.31.230:8000/deploy/init.sh|sh'

  # site
  ansible -i hosts site -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_kubelet.sh && sh install_kubelet.sh nfsadmin phpmyadmin adminmongo es elk prom alertmanager'

  # nginx
  echo "> site nginx"
  ansible -i hosts nginx -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_nginx.sh && sh install_nginx.sh'
}

install_k8s() {
  # master
  ansible -i hosts master -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_kubelet.sh && sh install_kubelet.sh master'

  # node  
  ansible -i hosts node -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_kubelet.sh && sh install_kubelet.sh node'
}

install_cloudos() {
  # db 
  ansible -i hosts db -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_mysql.sh && sh install_mysql.sh openbridge Admin@123'
  ansible -i hosts db -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_redis.sh && sh install_redis.sh'
  ansible -i hosts db -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_ldap.sh && sh install_ldap.sh'

  # cloudos
  ansible -i hosts cloudos -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_cloudos.sh && sh install_cloudos.sh'

  # dev
  ansible -i hosts dev -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_kubelet.sh && sh install_kubelet.sh gitlab svnadmin nexus jenkins sonar swagger'
  # nginx
  echo "> nginx"
  ansible -i hosts nginx -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_nginx.sh && sh install_nginx.sh cloudos'

  # registry
  echo "> registry"
  ansible -i hosts registry -m shell -a 'curl -O http://runtime.service.ob.local:8000/deploy/install_kubelet.sh && sh install_kubelet.sh registry'
}

install_new() {
  terraform destroy
  terraform apply
}

ansible -i hosts all -a uptime
for i in $*;do 
  echo "===========> exec: $i"
  eval "install_$i"
done
